package org.edu.modules.oa.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.edu.modules.oa.entity.VeFileFilesEntity;
import org.edu.modules.oa.entity.VeOaMobileMsgEntity;
import org.edu.modules.oa.entity.VeOaNewsEntity;
import org.edu.modules.oa.mapper.IVeFileFilesMapper;
import org.edu.modules.oa.mapper.IVeOaMobileMessageMapper;
import org.edu.modules.oa.mapper.IVeOaNewsMapper;
import org.edu.modules.oa.service.IVeOaMobileMsgService;
import org.edu.modules.oa.vo.VeOaMobileMsgExportVo;
import org.edu.modules.oa.vo.VeOaNewsExportVo;
import org.edu.modules.oa.vo.VeOaNewsVo;
import org.edu.modules.oa.vo.VeOaNoticeExportVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class VeOaMobileMsgServiceImpl extends ServiceImpl<IVeOaMobileMessageMapper, VeOaMobileMsgEntity>   implements IVeOaMobileMsgService {
    @Resource
    private IVeOaMobileMessageMapper iVeOaMobileMessageMapper;




    //显示表格
    @Override
    public HashMap<String, Object> showTable(Integer startPage, Integer pageSize, VeOaMobileMsgEntity veOaMobileMsgEntity) {
//        System.out.println("查询条件"+veOaNoticeEntity);
        QueryWrapper<VeOaMobileMsgEntity> queryWrapper=
        new QueryWrapper<VeOaMobileMsgEntity>()
                .like("content",veOaMobileMsgEntity.getContent())
                .eq("is_deleted",0)
                .orderByDesc("create_time");
        Page<VeOaMobileMsgEntity> list = iVeOaMobileMessageMapper.selectPage(new Page<>(startPage, pageSize),
                queryWrapper );


        int count = iVeOaMobileMessageMapper.selectCount(queryWrapper);

        HashMap<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("count", count);

        // 查询表格总行数
        return map;
    }

    @Override
    public List<VeOaMobileMsgExportVo> xporte() {
        // 拼接查询条件
        QueryWrapper<VeOaMobileMsgEntity> tableWrapper = new QueryWrapper<>();
        tableWrapper.eq("is_deleted",0);

        // 查询加油表的所有数据
        List<VeOaMobileMsgEntity> entitylist =iVeOaMobileMessageMapper.selectList(tableWrapper);

        // 表格集合的VO
        List<VeOaMobileMsgExportVo> voList=new ArrayList<>();
        // 把查出来的东西加入到表格VO里面去
        for(VeOaMobileMsgEntity entity:entitylist){
            VeOaMobileMsgExportVo vo =new VeOaMobileMsgExportVo();
            vo.setId(entity.getId());

            vo.setContent(entity.getContent());

//            vo.setCreateTime(entity.getCreateTime());
            vo.setReaders(entity.getReaders());
            if("".equals(entity.getReaders())){
                vo.setReaders("所有用户");
            }
            vo.setCreateBy(entity.getCreateBy());
            vo.setMsgType(entity.getMsgType());



            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            vo.setCreateTime(formatter.format(entity.getCreateTime()));
//            vo.setTixingUser(entity.getTixingUser());
            voList.add(vo);

        }
        return  voList;


    }

    @Override
    public int deleteRecord(Long id) {

        VeOaMobileMsgEntity v= new VeOaMobileMsgEntity();
        v.setId(id);
        v.setIsDeleted(1);
        int r2 = iVeOaMobileMessageMapper.updateById(v);

        return r2;

    }
/*
    @Override
    public List<VeOaNewsExportVo> export(VeOaNewsEntity veOaNewsEntity) {
        //创建查询的条件
        QueryWrapper<VeOaNewsEntity>wrapper = new QueryWrapper<>();
        if(veOaNewsEntity.getId()!=null&&veOaNewsEntity.getId()!=0){
            wrapper.eq("id",veOaNewsEntity.getId());

        }
        wrapper.eq("is_deleted",0);

        //查数据库，获取所有数据的集合
        List<VeOaNewsEntity>list = iVeOaNewsMapper.selectList(wrapper);
        //集合a是导出Excle的集合用的
        List<VeOaNewsExportVo>a = new ArrayList<>();
        for(VeOaNewsEntity v : list){
            VeOaNewsExportVo veOaNewsExportVo = new VeOaNewsExportVo();
            veOaNewsExportVo.setTitleStr(v.getTitleStr());
            veOaNewsExportVo.setContent(v.getContent());
            veOaNewsExportVo.setReaders(v.getReaders());
            veOaNewsExportVo.setCreateTime(v.getCreateTime());
            veOaNewsExportVo.setCreateBy(v.getCreateBy());
            //时间类型转换成字符串
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            veOaNewsExportVo.setCreateTime(formatter.format(v.getCreateTime()));

            a.add(veOaNewsExportVo);
        }
        return a;
    }
          */

}
